<?php
	class Database
	{
		private static $instance = NULL;

		private static $hostname = '';
		private static $database = '';
		private static $username = '';
		private static $password = '';
		private static $driver = '';

		private function __construct()
		{

		}

		private function __clone()
		{

		}

		public static function getInstance($hostname, $database, $username, $password, $driver = 'mysql')
		{
			if(!self::$instance)
			{
				self::$hostname = $hostname;
				self::$database = $database;
				self::$username = $username;
				self::$password = $password;
				self::$driver = $driver;

				switch(self::$driver)
				{
					case 'mysql':
						try
						{
							self::$instance = new PDO('mysql:host=' . self::$hostname . ';dbname=' . self::$database, self::$username, self::$password);
							self::$instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
						}
						catch(Exception $e)
						{
							throw new Exception("PDO Error " . $e);
						}
						break;
					
					default:
						throw new Exception("Invalid database driver.");
						break;
				}
			}
			return self::$instance;
		}
	}
?>